import { LoginForm, Profile, Token } from '@/types/data'
import http from '@/utils/http'
import { AxiosPromise } from 'axios'
// interface MyAxiosPromise extends AxiosPromise<TextDecoderOptions>
export type MyAxiosPromise<T> = AxiosPromise<{ data: T; message: string }>
// 登录
export function authorizationsPost (data: LoginForm): MyAxiosPromise<Token> {
  return http({ url: 'authorizations', method: 'post', data })
}
// 获取验证码
export function smsCodes (mobile: string) {
  return http({ url: `sms/codes/${mobile}`, method: 'get' })
}
// 获取用户信息
export function user (): MyAxiosPromise<Profile> {
  return http({ url: 'user', method: 'get' })
}
// 获取用户个人信息
export function userProfile () {
  return http({ url: 'user/profile', method: 'get' })
}
// 编辑个人资料
export function userProfilePatch (key: string, value: string) {
  return http({ url: 'user/profile', method: 'PATCH', data: { [key]: value } })
}
// 编辑用户头像
export function userPhoto (data: FormData) {
  return http({ url: 'user/photo', method: 'PATCH', data })
}
// 刷新token
// export function authorizationsPut ():any {
//   return http({
//     url: 'authorizations',
//     method: 'put',
//     noToken: true,

//   })
// }
